package com.service.schedule.tm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.DateUtils;
import com.common.StringUtils;
import com.common.http.HttpResult;
import com.dao.tm.PlanDao;
import com.model.tm.PlanModel;
import com.service.external.tm.TmService;

@Service("TmsScheduleService")
public class TmsScheduleService {
	static final Logger logger = LoggerFactory.getLogger(TmsScheduleService.class);

	@Autowired
	PlanDao planDao;
	@Autowired
	TmService tmService;

	// 获取运单号
	public void getTransportCode() {
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
//		hashMap.put("tms_transportCode", "1");
		hashMap.put("startTime", DateUtils.addDays(DateUtils.getCurrentDate(), -10));
		List<PlanModel> planModels = planDao.selectList(hashMap);
		List<String> orderList = new ArrayList<String>();
		for (PlanModel planModel : planModels) {
			if (StringUtils.isNotNull(planModel.getGodNum())) {
				orderList.add(planModel.getGodNum());
			}
		}

		String string = String.join(",", orderList);
		HttpResult httpResult = tmService.getYDH(string);
		List<Object[]> arrayListResult = (List<Object[]>) httpResult.getData();
		for (Object[] arr : arrayListResult) {
			PlanModel planModel = new PlanModel();
			planModel.setTransportCode(arr[0].toString());
			planModel.setGodNum(arr[1].toString());
			planModel.setTmDriver(arr[2].toString());
			planModel.setTmCar(arr[3].toString());
			planModel.setTmTank(arr[4].toString());
			planModel.setTmCarrierName(arr[5].toString());
			planDao.update(planModel);
		}
	}

}
